package com.software.process.now

import com.software.util.{DBTools, SparkSql}
import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.{DataFrame, SaveMode}


object SelectByTime {
  Logger.getLogger("org").setLevel(Level.ERROR)

  def main(args: Array[String]): Unit = {
    val spark = DBTools.getSession("AirQuailty","local")
    val airData = DBTools.redFile("csv","D:\\csv\\date.csv",spark)

    //hour
    airData.createOrReplaceTempView("beijing_hour")

    val selectByHour: DataFrame = {
      spark.sql(SparkSql.selectByHour)
    }

    DBTools.WriteMySql("Select_By_Hour",selectByHour,SaveMode.Overwrite)

    //day
    airData.createOrReplaceTempView("beijing_day1")

    val selectByDay: DataFrame = {
      spark.sql(SparkSql.selectByDay1)
    }

    selectByDay.createOrReplaceTempView("beijing_day2")
    val selectByDay_Two: DataFrame = {
      spark.sql(SparkSql.selectByDay2)
    }

    DBTools.WriteMySql("Select_By_Day",selectByDay_Two,SaveMode.Overwrite)

    //month
    airData.createOrReplaceTempView("beijing_month1")

    val selectByMonth: DataFrame = {
      spark.sql(SparkSql.selectByMonth1)
    }

    selectByMonth.createOrReplaceTempView("beijing_month2")
    val selectByMonth_Two: DataFrame = {
      spark.sql(SparkSql.selectByMonth2)
    }

    DBTools.WriteMySql("Select_By_Month",selectByMonth_Two,SaveMode.Overwrite)
  }
}
